{include file="admin@public:header" /}
{block name="centent"}
<div class="x-body layui-anim layui-anim-up">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="menu_name" class="layui-form-label">
                <span class="x-red">*</span>文章标题
            </label>
            <div class="layui-input-block">
                <input type="text" id="menu_name" name="title" required="required" lay-verify="menu_name"
                       autocomplete="off" class="layui-input" value="{$result.title}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="menu_type" class="layui-form-label">
                <span class="x-red">*</span>文章分类
            </label>
            <div class="layui-input-block">
                <select id="menu_type" name="cate_id" lay-verify="">
                    <option value="0">默认分类</option>
                    {volist name="$menu" id="vo"}
                    <option value="{$vo.id}" {if condition="$result.cate_id eq $vo.id"}selected{/if}>{$vo.cate_name}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">文章封面</label>
            <div class="layui-input-inline" style="width: 50%">
                <input type="text" name="cover" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input" value="{$result.cover}">
                <input type="hidden" name="path" value="{$result.path}">
            </div>
            <button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>上传封面
            </button>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"></label>
            <div class="layui-input-inline" style="width: 50%">
                <img src="{$result.cover}" alt="" width="100px">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文章状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="0" title="隐藏">
                <input type="radio" name="status" value="1" title="显示" checked>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">文章描述</label>
            <div class="layui-input-block">
                <textarea name="intro" placeholder="请输入文章的简单描述,可留空" class="layui-textarea">{$result.intro}</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">文章内容</label>
            <div class="layui-input-block">
                <input type="hidden" name="id" value="{$result.id}">
                <textarea id="editor" name="content" placeholder="请输入文章的简单描述,可留空" class="layui-textarea" style="height: 600px">{$result.content}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">
                修改
            </button>
        </div>
    </form>
</div>
{/block}
<script type="text/javascript" charset="utf-8" src="/static/uediter/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/uediter/ueditor.all.min.js"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="/static/uediter/lang/zh-cn/zh-cn.js"></script>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            menu_name: function(value){
                if(value.length < 0){
                    return '分类名称不能为空';
                }
            }
        });

        //监听提交
        form.on('submit(add)', function(data){
            $.ajax({
                type: "POST",
                url: "{:url('article/update')}",
                data: data.field,
                dataType: "json",
                success: function(data){
                    if (data.code) {
                        layer.alert("修改成功", {icon: 6},function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(data.msg);
                    }
                }
            });
            return false;
        });
    });
    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: 'upload' //上传接口
            ,done: function(res){
                //上传完毕回调
                if (res.code) {
                    $('input[name="cover"]').val(res.data.path);
                    $('input[name="path"]').val(res.data.path_url);
                } else {
                    layer.msg(res.msg);
                }
            }
        });
    });

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');


    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
</script>